Hi. I got a problem with my dxl, and I can't see the mistake. The thing is, I want to export to excel, the objects information of some attributes, those attributes were on a list that I created on the beginning of the code, this objects are from some modules that I want, no other one should be export. The thing is that when the dxl is running, he read modules that I didn't say I wanted to read. I think the problem is on matches in the end of the code, but I got stuck and dont know how to proceed, and since it isn't working I can't see if the rest of the code is working as well. If someone can give me a tip, I appreciate.
pragma runLim,0
#include <utils/ole.inc>
#include <utils/doctools/itfutil.inc>
/*===========================================
Variables for Excel Exportation
=============================================*/
checkPlatform "Microsoft Excel" // ???
OleAutoObj objExcel = null
OleAutoObj objWorkbooks = null
OleAutoObj objWorkbook = null
OleAutoObj objSheet = null
OleAutoObj objCell = null
OleAutoArgs args = create
/*===========================================
Variables for Word Exportation
=============================================*/
OleAutoObj objWord = null
OleAutoObj objDocuments = null
OleAutoArgs autoArgs = create
/*===========================================
BaselineSets and Attribute lists
=============================================*/
Skip baselineSets = create // cache current baselines
string aux
// CAS list
Skip attrListBRU = create
put(attrListBRU, 1, "Object Text")
put(attrListBRU, 3, "my attr1")
put(attrListBRU, 4, "my attr2")
put(attrListBRU, 5, "my attr3")
Skip attrList = create
/*=========================================================================================
Excel Exportation Functions
=========================================================================================*/
bool excelInit() {
objExcel = connectToApp(cObjExcelApplication, "Excel")
if (null objExcel) return false
// makeVisible objExcel
// get workbooks collection
checkRes(oleGet(objExcel,cPropertyWorkbooks,objWorkbooks))
if (null objWorkbooks) {
ack "Unable to get workbooks collection"
return false
}
// add one
checkRes(oleMethod(objWorkbooks, cMethodAdd))
// get active workbook
checkRes(oleGet(objExcel,cPropertyActiveWorkbook,objWorkbook))
if (null objWorkbook) {
ack "Unable to get active workbook"
return false
}
// get active sheet
checkRes(oleGet(objWorkbook,cPropertyActiveSheet,objSheet))
if (null objSheet) {
ack "Unable to get active sheet"
return false
}
return true
}
////////////////////////////////////////////////////////////////////
//////////// Changes int to letters (excel columns) ////////////////
///////////////////////////////////////////////////////////////////
string intToCol(int i) {
string s = ""
if ((i>=1) && (i<=256))
{
int d1 = (i-1) / 26
int d2 = (i-1) % 26
if (d1 > 0) {
s = charOf( d1-1 + intOf('A')) ""
}
s = s charOf( d2 + intOf('A')) ""
}
else
{
if (i>256){
ack "Too many columns"
}
else{
ack "Invalid column reference :" i ""
}
halt
}
return (s)
}
Regexp dateCheck = regexp "^([0-9]+-)+[0-9]+$"
void setCell(int row, int col, string s) {
closeIfNonNull objCell
clear(args)
put(args, (intToCol col) row "")
oleGet(objSheet, cMethodRange,args, objCell)
// Put here the correct Object Text title for each formal module.
if(s == "Object Text") {
s = "my name"
}
if (null objCell) {
ack "Unable to get cell object"
halt
}
// Excel considers string starting with an equal character (=) to be an excel formula
// hence it throws an error "OLE method failed". To avoid this we append "'" before the string.
if( s[0:0] == "=" || s[0:0] == "+" || s[0:0] == "-" || s[0:0] == "@" || s[0:0] == ">" || s[0:0] == "<" || s[0:0] == "?" || s[0:0] == ";" ||dateCheck s )
{
s = "'" s
}
checkRes(olePut(objCell, cPropertyValue, s))
}
string headingLong(Object o) {
string headingStr = o.AHeading ""
string textStr = o.ALongText ""
if (null headingStr) {
return textStr
}
if (null textStr) {
return headingStr ""
}
return headingStr "\n" textStr ""
}
void doExcel(Module &m) {
string fullModName
fullModName = fullName(m)
Skip res
int row = 0
int col
string attr
string s, sName
Object o
attrList = attrListBRU
if (!excelInit) {
delete excelTrigger
return
}
bool cTitlesIncluded = false
// Includes Baseline Number.
row++
col = 1
s = fullName(m)
setCell(row, col, s)
string tag
// Get spreadsheet name
checkRes(olePut(objSheet, "Name", "Data"))
// Insert 'received' content.
for o in m do{
// Insert column titles just one time.
tag = "[" (m)."Prefix" o."Absolute Number" "]"
if(!cTitlesIncluded){
row++
col = 1
setCell(row, col, "Tag")
for attr in attrList do{
col++
setCell(row, col, attr)
}
cTitlesIncluded = true
}
row ++
col = 1
setCell(row, col, tag)
for attr in attrList do{
col++
setCell(row, col, o.attr "")
}
}
// Save excel file
clear(autoArgs)
string xlsName = "C:\\Export\\" fullModName ".xls"
put(autoArgs, xlsName)
checkRes(oleMethod(objWorkbook, "SaveAs", autoArgs))
// Close workbook
checkRes(oleMethod(objWorkbook, "Close"))
disconnectFromApp objExcel
}
bool matchPrj(string prjName){
if(matches("(_)", prjName)) return false
return true
}
// All formal modules inside folders.
bool matchType(string modName){
if (matches("(specific folder)", modName)){
return true
}
return false
}
Project pProj = project "path"
Module m
Item itemRef
Skip modNameList = create
string parentPrj, parentFolder, moduleName, fullModName
int count = 0
DB progressDB = create "Progress test"
for itemRef in pProj do{
if (type(itemRef) "" == "Formal"){ // Look up just formal modules.
moduleName = name(itemRef)
parentPrj = fullName(getParentProject(itemRef))
if(matchPrj(parentPrj)){ // Just for some projects.
parentFolder = fullName(getParentFolder(itemRef))
if(matchType(parentFolder)){ // Just for some projects.
if((matches("Module name1", moduleName))||
(matches("Module name2", moduleName))||
(matches("Module name3", moduleName)))
{
put(modNameList, name(itemRef), fullName(itemRef))
count++
}
}
}
}
}
for fullModName in modNameList do{
m = read(fullModName, true)
fullModName "\n"
doExcel(m)
close(m)
}
infoBox "Done."
progressStop
delete(modNameList)
braolive - Tue Feb 11 13:38:05 EST 2014 |
Re: Export from several specifics modules Just before the doExcel(m) you have the following statement:
fullModName "\n"
Not sure what this is suppose to do. Hope this helps, Greg |
Re: Export from several specifics modules GregM_dxler - Tue Feb 11 16:47:09 EST 2014 Just before the doExcel(m) you have the following statement:
fullModName "\n"
Not sure what this is suppose to do. Hope this helps, Greg You're right. It made it run, but now it show the OLE method failed. In this case I have used the same code as the DOORS excel file from their standard dxl, it should not appear from what I understand. Or at least this is what I think when I copy and paste their dxl and made only small modifications. Anyway, thanks for the help, I havent seen the fullModName "\n" This is the error I get :
OLE problem: The file could not be accessed. Try one of the following:
|
Re: Export from several specifics modules braolive - Wed Feb 12 05:09:18 EST 2014 You're right. It made it run, but now it show the OLE method failed. In this case I have used the same code as the DOORS excel file from their standard dxl, it should not appear from what I understand. Or at least this is what I think when I copy and paste their dxl and made only small modifications. Anyway, thanks for the help, I havent seen the fullModName "\n" This is the error I get :
OLE problem: The file could not be accessed. Try one of the following:
Hello braolive,
with string xlsName = "C:\\Export\\" fullModName ".xls" you try to save the file with an invalid path, becaus fullModName (which you set to fullName(m)) does always contain "/" characters which are not allowed in filenames. If you simply use name(m) instead of fullModName the error message should disapear, - Michael
|
Re: Export from several specifics modules MichaelGeorg - Wed Feb 12 07:02:24 EST 2014 Hello braolive,
with string xlsName = "C:\\Export\\" fullModName ".xls" you try to save the file with an invalid path, becaus fullModName (which you set to fullName(m)) does always contain "/" characters which are not allowed in filenames. If you simply use name(m) instead of fullModName the error message should disapear, - Michael
It is working. Thank you guys, |